#include "../../../common/data_mysql.hpp"
#include "../../../odb/cheat_session_member.hxx"
#include "cheat_session_member-odb.hxx"
#include <mysql/mysql.h>
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式, false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下, 用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下, 用于指定日志输出等级");  //trace default 0

void append_test(xchat::ChatSessionMemberTable& member_table)
{
    xchat::ChatSessionMember member1("会话ID1", "f7aa-b126b9c7-0001");
    //xchat::ChatSessionMember member2("会话ID1", "用户ID2");
    //xchat::ChatSessionMember member3("会话ID2", "用户ID3");
    //member_table.append(member1);
    //member_table.append(member2);
    member_table.append(member3);
}

void multi_append_test(xchat::ChatSessionMemberTable& member_table)
{
    xchat::ChatSessionMember member1("会话ID3", "用户ID1");
    xchat::ChatSessionMember member2("会话ID3", "用户ID2");
    xchat::ChatSessionMember member3("会话ID3", "用户ID3");
    std::vector<xchat::ChatSessionMember> members = {member1, member2, member3};
    member_table.append(members);
}

void remove_test(xchat::ChatSessionMemberTable& member_table)
{
    xchat::ChatSessionMember member3("会话ID2", "用户ID3");
    member_table.remove(member3);
}

void get_member_test(xchat::ChatSessionMemberTable& member_table)
{
    auto uid_lists = member_table.members("会话ID1");
    for(auto uid : uid_lists)
    {
        std::cout << uid << std::endl;
    }
}

void remove_session_test(xchat::ChatSessionMemberTable& member_table)
{
    member_table.remove("会话ID3");
}

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    
    xchat::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = xchat::ODBFactory::create("root", "299274142", "127.0.0.1", "xchat", "utf8", 0, 1);

    xchat::ChatSessionMemberTable member_table(db);

    append_test(member_table);
    //multi_append_test(member_table);
    //remove_test(member_table);
    //get_member_test(member_table);
    //remove_session_test(member_table);

    return 0;
}